package com.example.springboot_jap_model.utils;

import com.example.springboot_jap_model.constant.Constant;
import com.example.springboot_jap_model.domain.RespEntity;
import com.example.springboot_jap_model.enums.RespEntityEnum;

/**
 * 使用 enums 模板化返回值
 */
public class RespEntityUtils {
    /**
     * 正确返回
     * @param object
     * @return
     */
    public static RespEntity success(Object object) {

        return new RespEntity(0, Constant.SUCCESS,object);
    }

    /**
     * 枚举类型 无返回 数据
     * @param respEntityEnum
     * @return
     */
    public static RespEntity success(RespEntityEnum respEntityEnum) {

        return new RespEntity(respEntityEnum.getCode(), respEntityEnum.getMsg(),null);
    }



    /**
     * 无返回 数据
     * @return
     */
    public static RespEntity success(){
        return new RespEntity(0,Constant.SUCCESS,null);
    }


    /**
     * 错误返回
     * @param code
     * @param msg
     * @return
     */
    public static RespEntity error(Integer code,String msg){
        return new RespEntity(code,msg,null);
    }
    /**
     * 枚举类型 无返回 数据
     * @param respEntityEnum
     * @return
     */
    public static RespEntity error(RespEntityEnum respEntityEnum) {

        return new RespEntity(respEntityEnum.getCode(), respEntityEnum.getMsg(),null);
    }
}
